// Getting Geo Location 
function getGeoLocation() {
	
	if(navigator.geolocation) {
		
		navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
	}
	else {
		
		document.getElementById("errorMsg").innerText = "ERROR: browser does not support geo location";
	}
}

// Getting Geo Location success callback
function successCallback(position) {

	// Output the coordinates
	document.getElementById("latitudeRes").innerHTML = "Latitude: " + position.coords.latitude;
	document.getElementById("longitudeRes").innerHTML = "Longitude: " + position.coords.longitude;
	
	// Show location on Google Map
	var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
	
	var myOptions = {
	      zoom: 13,
	      center: latlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
	
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	var marker = new google.maps.Marker({
	      position: latlng, 
	      map: map, 
	      title:"Your Location"
	  });
}

// Getting Geo Location error callback
function errorCallback(error) {
	
	switch(error.code) {
		
		case error.TIMEOUT:
			document.getElementById("errorMsg").innerHTML = "ERROR: " + error.message;
			break;
			
		default:
			document.getElementById("errorMsg").innerHTML = "ERROR: " + error.message;
	};
}